﻿Imports DTO
Imports System.Data.OleDb

Public Class PhieuThuDAO
    Public Shared Function GetPhieuThuAll() As DataTable
        Dim sql As String = "select * from PHIEUTHU"
        Return DatabassProvider.ExcuQuery(sql)
    End Function

    Public Shared Sub Insert(ByVal pt As PhieuThuDTO)
        Dim sql As String = "insert into PHIEUTHU(NgayThu,SoTienThu,MaKhachHang) values('" & pt.NgayThu & "'," & pt.SoTienThu & "," & pt.MaKhachHang & ")"
        DatabassProvider.ExcuNonQuery(sql)
    End Sub

    Public Shared Sub Update(ByVal pt As PhieuThuDTO)
        Dim sql As String = "Update  PHIEUTHU set NgayThu =('" & pt.NgayThu & "'),SoTienThu=(" & pt.SoTienThu & ") where MaPhieuThu=" & pt.MaPhieuThu & ""
        DatabassProvider.ExcuNonQuery(sql)
    End Sub

    Public Shared Function Delete(ByVal pt As PhieuThuDTO) As Boolean
        Try
            Dim sql As String = "delete from PHIEUTHU where MaPhieuThu= " & pt.MaPhieuThu & ""
            DatabassProvider.ExcuNonQuery(sql)
            Return True
        Catch
            Return False
        End Try
    End Function

    Public Shared Function GetPhieuThuByMa(ByVal Ma As Integer) As PhieuThuDTO
        Dim sql As String = "select * from PHIEUTHU where MaPhieuThu=" & Ma & ""
        Dim dt As DataTable = DatabassProvider.ExcuQuery(sql)
        If dt.Rows.Count = 0 Then
            Return Nothing
        Else
            Dim pt As New PhieuThuDTO()
            pt.MaPhieuThu = CInt(Fix(dt.Rows(0).ItemArray(0)))
            Return pt
        End If

    End Function

    Public Shared Function GetPhieuThuCondition(ByVal MaPhieuThu As Integer) As DataTable
        Dim sql As String = "select * from PHIEUTHU,KHACHHANG where MaPhieuThu = " & MaPhieuThu
        Return DatabassProvider.ExcuQuery(sql)
    End Function
End Class
